package com.sample.base.adapter;

import android.view.View;

import androidx.annotation.NonNull;
import androidx.databinding.ViewDataBinding;

import com.loyal.adapter.BaseListAdapter;
import com.sample.base.adapter.holder.ListBindHolder;

import java.util.List;

public abstract class BaseBindAdapter<T, B extends ViewDataBinding> extends BaseListAdapter<T, ListBindHolder<B>> {

    public BaseBindAdapter() {
        super();
    }

    public BaseBindAdapter(List<T> arrList) {
        super(arrList);
    }

    public abstract int variableId();

    @Override
    public ListBindHolder<B> createViewHolder(View view) {
        return new ListBindHolder<>(view);
    }

    @Override
    public void onViewHolder(@NonNull ListBindHolder<B> holder, int position) {
        B binding = holder.getBinding();
        T text = getItem(position);
        binding.setVariable(variableId(), text);
        binding.executePendingBindings();
    }
 }
